import {kankan} from "./kankan";
import {PluginManager} from "./plugin_manager";

var registry = {
    scripts: {
        search: {
            id: "search-content-script",
            js: ["dist/search.bundle.js"],
            matches: ["http://localhost:8086/*"],
        }
    },
    registerSearchScript() {
        chrome.scripting.registerContentScripts([
            registry.scripts.search,
        ]);
    }
};

var onMessageListener = function(message, sender, cb) {
    switch(message.action) {
        case "getSearchPlugins":
            console.log(PluginManager._plugins);
            cb({
                tabId: sender.tab.id,
                plugins: PluginManager._plugins,
                pluginInterfaces: PluginManager._pluginInterfaces
            });
            break;
    }
}
var installed = function({reason}) {
    if (reason == chrome.runtime.OnInstalledReason.INSTALL) {
        console.info("installed");
    }
    // pluginManager.init();
    registry.registerSearchScript();
};
function main() {
    chrome.runtime.onInstalled.addListener(installed);
    chrome.runtime.onMessage.addListener(onMessageListener);

}

export default main();